package com.api.controller;

import com.common.apiResult.ApiController;
import com.common.exception.ApiException;
import com.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.mp.api.WxMpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName WeChatController
 * @Description 微信公众平台相关操作
 * @Date 2020/9/30 10:26
 * Create By Renbowen
 */
@RequestMapping(value = "/api/weChat")
@Slf4j
public class WeChatController extends ApiController {

    // wxJava公众号操作API
    private final WxMpService wxMpService;

    public WeChatController(WxMpService wxMpService) {
        this.wxMpService = wxMpService;
    }

    /**
     *  Create By Renbowen
     *  @Date: 2020/9/30 10:31
     *  @Description: 微信分享页面-获取微信加密信息
     */
    @RequestMapping(value = "/getSignature")
    @ResponseBody
    public WxJsapiSignature toTranscript(String urls) {
        if (StringUtils.isBlank(urls)) {
            throw new ApiException( "链接为空！");
        }
        try {
            return wxMpService.createJsapiSignature(urls);
        } catch (Exception e) {
            log.error("获取分享所需要的参数失败！报错信息:{{}}",e.getMessage());
            e.printStackTrace();
        }
        return null;
    }


}
